/*
 * dns.h
 *
 *  Created on: Dec 25, 2013
 *      Author: killerg
 */

#ifndef DNS_H_
#define DNS_H_

#include <functional>
#include <string>

#include <event2/dns.h>
#include <event2/event.h>
#include <event2/util.h>

void dns_callback(int result, char type, int count, int ttl, void *addresses, void *arg);

struct dns_t {
    typedef std::function<void(const std::string &host, const std::string &ip)> result_cb_t;
    struct pend_t {
        dns_t* dns;
        evdns_request* req;
        std::string host;
        result_cb_t cb;
    };

    bool init();
    void destroy();
    void update();
    bool query_ip(const char* host, result_cb_t cb);
    event_base* base;
    evdns_base* dns_base;
};



#endif /* DNS_H_ */
